let body = document.querySelector("body")
let rand = (num) => {
    return Math.floor(Math.random() * num)
}
window.onclick = (event) => {
    // event --> 光标元素
    let x = event.clientX
    let y = event.clientY
    // 创建元素
    let heart = document.createElement("span")
    // 给元素添加内容添加样式
    heart.innerText = "❤"
    heart.style.position = "absolute"
    heart.style.left = x - 8 + "px"
    heart.style.top = y - 8 + "px"
    heart.className = "span"
    heart.style.color = "rgb(" + rand(255) + "," + rand(255) + "," + rand(255) + ")"
    // 将创建的元素拼接到页面
    body.appendChild(heart)
    setTimeout(() => {
        // 两秒之后将拼接的元素删除
        body.removeChild(heart)
    }, 2000)
}